<?php
/**
 *	FILENAME: 		/libraries/devices.php
 *	DESCRIPTION:	This library contains and returns information related MyNova Mobile device records.
 *	AUTHOR:			Casey Burkhardt
 *	VERSION:		1.0.0
 *	LAST MODIFIED:	12/31/2009
 **/

require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/database.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/users.php");


/**
 *	DESCRIPTION:	Returns the primary `devices`.`udid` value of a device record given a User ID value.
 **/
function getPrimaryUDIDValue($uid) {
    connectToDatabase();
    $sql = "SELECT *
			FROM `devices`
			WHERE `uid` = '" . $uid . "' 
			AND `primary_device` = '1';";
    $result = mysql_query($sql) or die(mysql_error());
    if (mysql_num_rows($result) > 0) {
        while ($row = mysql_fetch_assoc($result)) {
            return $row["udid"];
        }
    } else {
        return FALSE;
    }
}

/**
 *	DESCRIPTION:	Returns the User ID value associated with a given primary device UDID value.
 **/
function getUIDValue($primaryUDID) {
    connectToDatabase();
    $sql = "SELECT *
			FROM `devices`
			WHERE `udid` = '" . $primaryUDID . "' 
			AND `primary_device` = '1';";
    $result = mysql_query($sql) or die(mysql_error());
    if (mysql_num_rows($result) > 0) {
        while ($row = mysql_fetch_assoc($result)) {
            return $row["uid"];
        }
    } else {
        return FALSE;
    }
}
?>